/*
**  Copyright (c) 2014 Michael Liu(michael.liu.point@gmail.com).
**
**  Project: Gateway Unified Management Platform
**  File:    cmapi.h
**  Author:  Michael
**  Date:    03/20/2014
**
**  Purpose:
**    Common Management API defines.
*/

#ifndef __CM_API_H__
#define __CM_API_H__

#ifdef __cplusplus
extern "C" {
#endif				/* __cplusplus */

/* Include files. */

#include "common.h"
#include "cmrc.h"
#include "dpmgr.h"
#include "eamgr.h"
#include "samgr.h"

/* Macro constant definitions. */

/*
#define CMAPI_DEBUG
*/

/* Type definitions. */

/* External function declarations. */

	extern e_ret cmapi_create_session(tcm_session * session, const char *name);
	extern e_ret cmapi_destroy_session(tcm_session * session);
	extern e_ret cmapi_require(tcm_session * session, int counter,
				   void *req_body, int req_size, void **rsp_body, int *rsp_size);

	extern e_ret dp_cmn_get_dev_optmode(tcm_session * session, unsigned char *mode);
	extern e_ret dp_cmn_set_dev_optmode(tcm_session * session, unsigned char mode);
	extern e_ret dp_cmn_set_dev_countryregion(tcm_session * session, unsigned int country_num);
	extern e_ret dp_cmn_get_dev_countryregion(tcm_session * session, unsigned int *country_num);
	extern e_ret dp_cmn_get_dev_mac(tcm_session * session, tdevmac * devmac);

	extern e_ret dp_if_br_setlinkcfg(tcm_session * session, const char *name,
					 tmask * mask, tbridge_if_linkcfg * linkcfg);
	extern e_ret dp_if_br_getlinkcfg(tcm_session * session, const char *name, void **linkcfg, int *linkcfg_size);

	extern e_ret dp_if_wlancli_setlinkcfg(tcm_session * session, const char *name,
					      tmask * mask, twlan_cli_if_linkcfg * linkcfg);
	extern e_ret dp_if_wlancli_getlinkcfg(tcm_session * session, const char *name,
					      void **linkcfg, int *linkcfg_size);
	extern e_ret dp_if_wlancli_getlinkstatus(tcm_session * session, const char *name,
						 twlan_cli_if_link_status ** aps);

	extern e_ret dp_if_wlancli_start_scan_aps(tcm_session * session, const char *name);
	extern e_ret dp_if_wlancli_stop_scan_aps(tcm_session * session, const char *name);
	extern e_ret dp_if_wlancli_query_scan_aps(tcm_session * session, const char *name,
						  twlan_cli_if_link_status ** aps);

	extern e_ret dp_if_wlanap_getlinkcfg(tcm_session * session, const char *name,
					     void **linkcfg, int *linkcfg_size);
	extern e_ret dp_if_wlanap_setlinkcfg(tcm_session * session, const char *name,
					     tmask * mask, twlan_ap_if_linkcfg * linkcfg);
	extern e_ret dp_if_wlanap_getlinkstatus(tcm_session * session, const char *name,
						twlan_ap_if_link_status ** clients);

	extern e_ret dp_if_ether_getlinkstatus(tcm_session * session, const char *name, teth_if_link_status ** status);

	extern e_ret dp_if_setnetcfg(tcm_session * session, const char *name, tmask * mask,
				     void *netcfg, int netcfg_size);
	extern e_ret dp_if_getnetcfg(tcm_session * session, const char *name, void **netcfg, int *netcfg_size);

	extern e_ret dp_if_getnetstatus(tcm_session * session, const char *name, void **netstatus, int *netstatus_size);

	extern e_ret sa_sm_verify_password(tcm_session * session, const char *password, unsigned char *ok);
	extern e_ret sa_sm_set_password(tcm_session * session, const char *password);
	extern e_ret sa_sm_get_password(tcm_session * session, char *password);
	extern e_ret sa_sm_get_qis(tcm_session * session, unsigned char *qis_done);
	extern e_ret sa_sm_set_qis(tcm_session * session, unsigned char qis_done);
	extern e_ret sa_sm_get_language(tcm_session * session, unsigned char *lang);
	extern e_ret sa_sm_set_language(tcm_session * session, unsigned char lang);
	extern e_ret sa_sm_get_uptime(tcm_session * session, t_date_time * datetime);
	extern e_ret sa_sm_get_datetime(tcm_session * session, t_date_time * datetime);
	extern e_ret sa_sm_set_datetime(tcm_session * session, t_date_time datetime);
	extern e_ret sa_sm_get_ntp(tcm_session * session, char *net_server);
	extern e_ret sa_sm_set_ntp(tcm_session * session, const char *net_server);
	extern e_ret sa_sm_get_timezone(tcm_session * session, unsigned int *timezone);
	extern e_ret sa_sm_set_timezone(tcm_session * session, unsigned int timezone);
	extern e_ret sa_sm_get_power_save(tcm_session * session, unsigned char *power_save);
	extern e_ret sa_sm_set_power_save(tcm_session * session, unsigned char power_save);
	extern e_ret sa_sm_reboot(tcm_session * session);
	extern e_ret sa_cm_dump_cfg(tcm_session * session, char *cfg_file);
	extern e_ret sa_cm_load_cfg(tcm_session * session, char *cfg_file);
	extern e_ret sa_cm_reset_cfg(tcm_session * session);
	extern e_ret sa_fm_get_version(tcm_session * session, char *version);
	extern e_ret sa_fm_local_upgrade(tcm_session * session, char *fm_name);
	extern e_ret sa_fm_start_fota_check(tcm_session * session);
	extern e_ret sa_fm_query_fota_check(tcm_session * session, char *version);
	extern e_ret sa_fm_cancel_fota_check(tcm_session * session);
	extern e_ret sa_fm_start_fota_upgrade(tcm_session * session);
	extern e_ret sa_fm_query_fota_upgrade(tcm_session * session);
	extern e_ret sa_fm_cancel_fota_upgrade(tcm_session * session);

/* Macro API definitions. */
#ifdef CMAPI_DEBUG
#define cmapi_error(fmt,...) \
	do { \
		printf("[ERROR] " __FILE__ "(" __S_LINE__ "): "  fmt, ##__VA_ARGS__);\
	} while(0)

#define cmapi_infor(fmt,...) \
	do { \
		printf("[INFOR] " __FILE__ "(" __S_LINE__ "): "  fmt, ##__VA_ARGS__);\
	} while(0)

#define cmapi_debug(fmt,...) \
	do { \
		printf("[DEBUG] " __FILE__ "(" __S_LINE__ "): "  fmt, ##__VA_ARGS__);\
	} while(0)

#define cmapi_trace_enter() \
	do { \
		printf("[ENTER] %s(): %s(%d)\n", __FUNCTION__, __FILE__, __LINE__);\
	} while(0)

#define cmapi_trace_exit() \
	do { \
		printf("[EXIT ] %s(): %s(%d)\n", __FUNCTION__, __FILE__, __LINE__);\
	} while(0)

#define cmapi_trace_line() \
	do { \
		printf("[CHECK] %s(): %s(%d)\n", __FUNCTION__, __FILE__, __LINE__);\
	} while(0)
#else				/* CMAPI_DEBUG */
#define cmapi_error(fmt,...)
#define cmapi_infor(fmt,...)
#define cmapi_debug(fmt,...)
#define cmapi_trace_enter()
#define cmapi_trace_exit()
#define cmapi_trace_line()
#endif				/* CMAPI_DEBUG */

#ifdef ASSERT
#undef ASSERT
#define ASSERT(x) \
  do {                                                                        \
      if (!(x)) {                                                             \
          cmapi_error("%s\n", # x);                                            \
          exit (-1);                                                          \
      }                                                                       \
  } while (0)
#endif

/* Global variable declarations. */

#ifdef __cplusplus
}				/* extern "C" */
#endif				/* __cplusplus */
#endif				/* __CM_API_H__ */
